<?
require("config.php");

$label = "Order List";

$table="cus_order";


if ($action=="search"){

	$ftime=strtotime($fy.'-'.$fm.'-'.$fd.' 00:00:00');
	$ttime=strtotime($ty.'-'.$tm.'-'.$td.' 23:59:59');

	if ($no) $nostr=' and no = '.$no;
	else $nostr='';

	if ($firstname) $namestr="%$firstname%";
	else $namestr='';
	if ($lastname) 	$namestr.="$lastname%";
	if ($namestr) 	$namestr=" and member_name like '$namestr'";
	
	if ($member_email) $emailstr=" and member_email like '%$member_email%'";
	else $emailstr='';
	
	if ($hkid) $hkidstr=" and hkid like'%$hkid%'";
	else $hkidstr='';
	

	$Query="SELECT 
	id,
	no,
	trans_no,
	member_name,
	member_email,
	purchase_date,
	shipping_status,
	order_status,
	delivery_date
	 
	FROM $table WHERE 
	purchase_date	between $ftime and $ttime
	$nostr
	$namestr
	$emailstr
	$hkidstr
	ORDER BY id DESC";

	$r=myQuery($Query);

}else{

	$Query="SELECT 
	id,
	no,
	trans_no,
	member_name,
	member_email,
	purchase_date,
	shipping_status,
	order_status,
	delivery_date
	FROM $table ORDER BY id DESC";

	$r=myQuery($Query);

}

require($rela_path . "inc/header1.php");
?>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>


<br>
<table width="90%" border="0" align="center">
  <tr> 
    <td>
	
	
	
	
	
	
	
<FORM ACTION="" METHOD=GET name="ask" id="ask">		  
		  
<input name="action" type="hidden" value="search">
		  
	
	<table border="0">
        <tr bgcolor="#CCCCCC"> 
          <td><div align="right">Order Date (DD-MM-YYYY)</div></td>
          <td>Name</td>
        </tr>
        <tr> 
          <td><div align="right">From :
            <select name="fd">
              <option value="1" selected>1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
              <option value="11">11</option>
              <option value="12">12</option>
              <option value="13">13</option>
              <option value="14">14</option>
              <option value="15">15</option>
              <option value="16">16</option>
              <option value="17">17</option>
              <option value="18">18</option>
              <option value="19">19</option>
              <option value="20">20</option>
              <option value="21">21</option>
              <option value="22">22</option>
              <option value="23">23</option>
              <option value="24">24</option>
              <option value="25">25</option>
              <option value="26">26</option>
              <option value="27">27</option>
              <option value="28">28</option>
              <option value="29">29</option>
              <option value="30">30</option>
              <option value="31">31</option>
            </select> 
              -
              <select name="fm">
                <option value="1" selected>1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
              </select>
              -
              <select name="fy">
                  <option value="2004" selected>2004</option>
                  <option value="2005">2005</option>
                  <option value="2006">2006</option>
                  <option value="2007">2007</option>
                  <option value="2008">2008</option>
                  <option value="2009">2009</option>
                  <option value="2010">2010</option>
              </select>
          </div></td>
          <td><input name="firstname" type="text" class="text" id="firstname">
            (First Name)</td>
        </tr>
        <tr> 
          <td><div align="right">To :
            <select name="td">
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
              <option value="7">7</option>
              <option value="8">8</option>
              <option value="9">9</option>
              <option value="10">10</option>
              <option value="11">11</option>
              <option value="12">12</option>
              <option value="13">13</option>
              <option value="14">14</option>
              <option value="15">15</option>
              <option value="16">16</option>
              <option value="17">17</option>
              <option value="18">18</option>
              <option value="19">19</option>
              <option value="20">20</option>
              <option value="21">21</option>
              <option value="22">22</option>
              <option value="23">23</option>
              <option value="24">24</option>
              <option value="25">25</option>
              <option value="26">26</option>
              <option value="27">27</option>
              <option value="28">28</option>
              <option value="29">29</option>
              <option value="30">30</option>
              <option value="31" selected>31</option>
            </select>
  -
  <select name="tm">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
    <option value="11">11</option>
    <option value="12" selected>12</option>
  </select>
  -
  <select name="ty">
        <option value="2004">2004</option>
        <option value="2005">2005</option>
        <option value="2006">2006</option>
        <option value="2007">2007</option>
        <option value="2008">2008</option>
        <option value="2009">2009</option>
        <option value="2010" selected>2010</option>
  </select>
          </div></td>
          <td><input name="lastname" type="text" class="text" id="lastname">
            (Last Name) </td>
        </tr>
        <tr>
          <td><div align="right">Order Number : </div></td>
          <td><input  name="no" type="text" class="text" id="no"></td>
        </tr>
        <tr>
          <td><div align="right"> HK ID Number : </div></td>
          <td><input  name="hkid" type="text" class="text" id="hkid2"></td>
        </tr>
        <tr>
          <td><div align="right">Email Address : </div></td>
          <td>            <input  name="member_email" type="text" class="text" id="member_email2" size="35"></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="button" onClick="MM_validateForm('no','','NinRange0:99999');return document.MM_returnValue" value="  Go  "> 
          <input name="listall" type="button" class="button" id="listall" onClick="MM_goToURL('parent','<?=$PHP_SELF?>');MM_returnValue"  value="List All"></td>
        </tr>
      </table>
</FORM>	  
	  
	  
	  
	  
	  
	  
    </td>
  </tr>
</table>
<br>
[ <a href="export_order.php?fd=<?=$fd?>&fm=<?=$fm?>&fy=<?=$fy?>&td=<?=$td?>&tm=<?=$tm?>&ty=<?=$ty?>&lastname=<?=urlencode($lastname)?>&firstname=<?=urlencode($firstname)?>&action=<?=$action?>&no=<?=$no?>&hkid=<?=$hkid?>&email=<?=$email?>">Export to EXCEL</a> ]
<br>
<br>
<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1" class="tb">
  <tr class="tbheader"> 
    <td width="25%"> 
      <div align="center">Order/Transaction No.</div>
    </td>
    <td width="20%"> 
      <div align="center">Customer</div>
    </td>
    <td width="25%"> 
      <div align="center">Order Date</div>
    </td>
    <td width="30%"> 
      <div align="center">Order/Shipping Status</div>
    </td>
  </tr>


<?
if ($r){	
	for ($i=0;$i<count($r);$i++){?>
  <tr class="tbcontent1"> 
    <td align="center"><a href="customer_order_detail.php?id=<?print($r[$i][0])?>"><?=str_pad($r[$i][1],5,'0',STR_PAD_LEFT)?><br><?print($r[$i][2])?></td>
    <td align="center"><?print($r[$i][3])?></td>
	<td align="left"><?=date('Y-m-d H:i:s',$r[$i][5])?></td>
	<td align="left"><?=$r[$i][7].'<br>'.$r[$i][6]?><? echo ($r[$i][6]=='Delivered')?' ('.date('Y-m-d',$r[$i][8]).')':'';?></td>
  </tr>
<?}
}?>


</table>
<br>
<br>
&nbsp;&nbsp; 
<?
require($rela_path . "inc/footer1.php");
?>
